//
//  ChoseTimeView.m
//  StockNetManager
//
//  Created by 小焘无量 on 2023/3/24.
//

#import "ChoseTimeView.h"

@interface ChoseTimeView()

@property (weak, nonatomic) IBOutlet UIDatePicker *datePickerView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomLayout;

@property (nonatomic, copy) void (^choseDateBlock)(NSDate *resultDate);

@end

@implementation ChoseTimeView

#pragma mark - LifeCycle

+(void)showMaxDate:(NSDate * _Nullable)maxDate minDate:(NSDate * _Nullable)minDate complate:(void(^)(NSDate *chosedDate))complate{
    ChoseTimeView *pickerView = [[ChoseTimeView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) maxDate:maxDate minDate:minDate];
    [kWindow addSubview:pickerView];
    [pickerView showWithAnimation];
    pickerView.choseDateBlock = ^(NSDate *date) {
        complate(date);
    };
}

-(instancetype)initWithFrame:(CGRect)frame maxDate:(NSDate * _Nullable)maxDate minDate:(NSDate * _Nullable)minDate{
    if (self = [super initWithFrame:frame]) {
        self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
        self.frame = frame;
        
        if (maxDate) {
            [self.datePickerView setMaximumDate:maxDate];
        }
        if (minDate) {
            [self.datePickerView setMinimumDate:minDate];
        }
        
        
        [self UIConfig];
    }
    return self;
}

-(void)UIConfig {
    self.bottomLayout.constant = HomeIndecatorHeight;
    self.alpha = 0;
}



#pragma mark - view layout

#pragma mark - Event Response

- (IBAction)cancelBtnAction:(id)sender {
    
    [self hidWithAnimation];
}
- (IBAction)sureBtnAction:(id)sender {
    
    if(self.choseDateBlock) {
        self.choseDateBlock(self.datePickerView.date);
    }
    
    [self hidWithAnimation];
    
}
- (IBAction)datePickerValueChange:(UIDatePicker *)sender {
    
    DLog(@"%@", [NSString  stringFromDate:sender.date]);
    
}

#pragma mark - Delegate,DataSource

#pragma mark - Network

#pragma mark - Method

-(void)showWithAnimation {
    
    WeakSelf;
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.alpha = 1;
    }];
}

- (void)hidWithAnimation {
    
    WeakSelf;
    [UIView animateWithDuration:0.15 animations:^{
        weakSelf.alpha = 0;
    } completion:^(BOOL finished) {
        [weakSelf removeFromSuperview];
    }];
    
}

#pragma mark - Set Get

#pragma mark - Lazy

@end
